#include "drive.h"
#include "ui_drive.h"

Drive::Drive(QWidget *parent,ArClientBase *client) :
    QDialog(parent),
    ui(new Ui::Drive)
{
    ui->setupUi(this);

    cliente = client;

    this->setFixedSize(this->geometry().width(),this->geometry().height());
    this->setAttribute(Qt::WA_DeleteOnClose);
}

Drive::~Drive()
{

    delete ui;

}

void Drive::on_button_forward_pressed()
{
    ArNetPacket packet;
    packet.doubleToBuf(100.0);
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(50.0);
    packet.doubleToBuf(0.0);
    cliente->requestOnce("ratioDrive",&packet);
}

void Drive::on_button_forward_released()
{
    ArNetPacket packet;
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(50.0);
    packet.doubleToBuf(0.0);
    cliente->requestOnce("ratioDrive",&packet);
}

void Drive::on_button_right_pressed()
{

    ArNetPacket packet;
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(-100.0);
    packet.doubleToBuf(50.0);
    packet.doubleToBuf(0.0);
    cliente->requestOnce("ratioDrive",&packet);

}

void Drive::on_button_right_released()
{
    ArNetPacket packet;
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(50.0);
    packet.doubleToBuf(0.0);
    cliente->requestOnce("ratioDrive",&packet);
}

void Drive::on_button_backward_pressed()
{
    ArNetPacket packet;
    packet.doubleToBuf(-100.0);
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(50.0);
    packet.doubleToBuf(0.0);
    cliente->requestOnce("ratioDrive",&packet);
}

void Drive::on_button_backward_released()
{
    ArNetPacket packet;
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(50.0);
    packet.doubleToBuf(0.0);
    cliente->requestOnce("ratioDrive",&packet);
}

void Drive::on_button_left_pressed()
{
    ArNetPacket packet;
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(100.0);
    packet.doubleToBuf(50.0);
    packet.doubleToBuf(0.0);
    cliente->requestOnce("ratioDrive",&packet);
}

void Drive::on_button_left_released()
{
    ArNetPacket packet;
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(0.0);
    packet.doubleToBuf(50.0);
    packet.doubleToBuf(0.0);
    cliente->requestOnce("ratioDrive",&packet);
}
